import React, { useEffect, useState } from 'react'
import moment from 'moment';
export default function ClockCom() {
  //声明状态
  let [time, setTime] = useState(moment().format('YYYY-MM-DD HH:mm:ss'));
  //启动定时器
  useEffect(() => {
    //定时器
    let timer = setInterval(() => {
      //更新状态
      setTime(moment().format('YYYY-MM-DD HH:mm:ss'));
    }, 1000);

    return () => {
      clearInterval(timer);
    }
  }, []);


  return (
    <div style={{padding: 20, display: 'inline-block', border: 'solid 1px #c90'}}>
      {time}
    </div>
  )
}
